package com.liuxl.db.bo;

import java.io.Serializable;

import com.liuxl.db.common.ColumnType;
/**
 * 数据库列信息
 * Created by LiuXiaoLong at 2021年1月13日
 */
public class Column implements Serializable{

	private static final long serialVersionUID = 5147571053412739181L;
	
	/** 列名 */
	private String name;
	
	/** 类型 */
	private ColumnType columnType;
	
	/** 长度 */
	private Integer length;
	
	/** 小数位数 */
	private Integer decimalDigits;
	
	private Boolean isNullable = true;
	
	public Column() {
		super();
	}
	
	

	public Column(String name, ColumnType columnType, Integer length, Integer decimalDigits, Boolean isNullable) {
		super();
		this.name = name;
		this.columnType = columnType;
		this.length = length;
		this.decimalDigits = decimalDigits;
		this.isNullable = isNullable;
	}



	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ColumnType getColumnType() {
		return columnType;
	}

	public void setColumnType(ColumnType columnType) {
		this.columnType = columnType;
	}

	public Integer getLength() {
		return length;
	}

	public void setLength(Integer length) {
		this.length = length;
	}

	public Integer getDecimalDigits() {
		return decimalDigits;
	}

	public void setDecimalDigits(Integer decimalDigits) {
		this.decimalDigits = decimalDigits;
	}

	public Boolean getIsNullable() {
		return isNullable;
	}

	public void setIsNullable(Boolean isNullable) {
		this.isNullable = isNullable;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/**
	 * 构建数据库列类型
	 * @return
	 */
	public  String bulidColumnType() {
		ColumnType columnType = this.getColumnType();
		Integer length = this.getLength();
		Integer decimalDigits = this.getDecimalDigits();
		switch (columnType) {
		case CHAR:
		case CHAR2:
		case NCHAR:
			return columnType.getValue()+"("+(length == null ? 32 : length)+")";
		case VARCHAR:
		case VARCHAR2:
		case NVARCHAR:
			return columnType.getValue() + "("+(length == null ? 255 : length)+")";
		case INT:
		case DATE:
		case DATETIME:
		case TIMESTAMP:
		case TEXT:
		case CLOB:
			return columnType.getValue();
		case DECIMAL:
		case NUMBER:
			return columnType.getValue() + "("+(length == null ? 5 : length)+","+(decimalDigits == null ? 2 : decimalDigits)+")";
		default:
			break;
		}
		return null;
	}
}
